package com.atguigu.schedule.controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/*
 * 增加日程的请求  /schedule/add
 * 查询日程的请求  /schedule/find
 * 修改日程的请求  /schedule/update
 * 删除日程的请求  /schedule/remove
 * 。。。。
 * */
@WebServlet("/schedule/*")
public class SysScheduleController extends BaseController {

    protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("add");
    }
    /* @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断此次请求的是 增 删 改 查？

      *//*  String requestURI = req.getRequestURI();  //schedule/add
        String[] split = requestURI.split("/");
        String methodName = split[split.length - 1];*//*
       *//* if (methodName.equals("add")) {
            //做增加处理
            add(req, resp);
        } else if (methodName.equals("find")) {
            //做查询处理
            find(req, resp);
        } else if (methodName.equals("update")) {
            //做修改处理
            update(req, resp);
        } else if (methodName.equals("remove")) {
            //做删除处理
            remove(req, resp);
        }*//*
        //使用反射通过方法名调用对应的方法
        Class<? extends SysScheduleController> aClass = this.getClass();
        //获取方法
        try {
            Method declaredMethod = aClass.getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
            //暴力破解方法的访问修饰符的限制
            declaredMethod.setAccessible(true);
            //执行方法
            declaredMethod.invoke(this, req, resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("add");
    }

    protected void find(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("find");
    }

    protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("update");
    }
    protected void remove(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("remove");
    }
*/

}
